package com.rpc.spring;

import com.rpc.api.ITestService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;

public class DefaultDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
//        DefaultBeanDefinitionScanner defaultClassPathScanner = new DefaultBeanDefinitionScanner(beanDefinitionRegistry);
//        defaultClassPathScanner.doScan("com.rpc.api");

        BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(com.rpc.impl.TestServiceImpl.class).getBeanDefinition();
        ((AbstractBeanDefinition) beanDefinition).setBeanClass(BaseMapperFactoryBean.class);
        ((AbstractBeanDefinition) beanDefinition).getPropertyValues().add("mapperInterface","com.rpc.api.ITestService");
        beanDefinitionRegistry.registerBeanDefinition("testService",beanDefinition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

    }
}
